/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-08-18 10:17:41
 * @LastEditors: GGB
 * @LastEditTime: 2021-08-18 11:10:11
 */
import 'package:bezier_chart/bezier_chart.dart';
import 'package:flutter/material.dart';
import 'package:flutter_data_center/components/loading.dart';
import 'package:flutter_data_center/controller/wristband_controller.dart';
import 'package:get/get.dart';

class WristbandDetailChart extends StatelessWidget {
  const WristbandDetailChart({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) =>
      GetBuilder<WristbandController>(builder: (_controller) {
        List<double> xAxis = [];
        List<DataPoint> dataPoints = [];
        if (_controller.detail == null) return Loading();
        for (var e in _controller.detail.rows) {
          double x = e.time.toDouble();
          double y = e.count.toDouble();
          xAxis.add(x);
          dataPoints.add(DataPoint(value: y, xAxis: x));
        }
        return Center(
          child: Container(
            height: 178,
            width: MediaQuery.of(context).size.width,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(15),
              // color: Colors.red,
              gradient: LinearGradient(
                  begin: Alignment.bottomCenter,
                  end: Alignment.topCenter,
                  colors: [
                    Color.fromRGBO(61, 255, 69, 0.8),
                    Color.fromRGBO(61, 255, 69, 0.2),
                  ]),
              boxShadow: [
                BoxShadow(
                  offset: Offset(0, 0),
                  blurRadius: 4,
                  color: Color.fromRGBO(0, 0, 0, 0.05),
                ),
              ],
            ),
            child: BezierChart(
              bezierChartScale: BezierChartScale.CUSTOM,
              xAxisCustomValues: xAxis,
              series: [
                BezierLine(
                  data: dataPoints,
                ),
              ],
              config: BezierChartConfig(
                verticalIndicatorStrokeWidth: 3.0,
                showVerticalIndicator: false,
                backgroundColor: Colors.transparent,
                snap: false,
                showDataPoints: false,
              ),
            ),
          ),
        );
      });
}
